import { size, IFormProps, pageSize, dateTimeFormat, dateFormat, formItemLayout, getFileList } from "../../utils/common";
import React from "react";
import { connect } from "dva";
import { Form, Row, Col, Button, Input, Table, Popconfirm, Select, DatePicker, Modal } from 'antd';
import { PaginationProps } from "antd/lib/pagination";
import moment from 'moment';
const Styles = require("../../styles/index.less");
import * as api from '../../api/api';
import Uploads from '../../components/Uploads';

export interface IRefitsPros extends IFormProps {
    user: any
}
class Refits extends React.PureComponent<IRefitsPros, any>{
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.search();
    }

    search = () => {
        this.getUserRefits();
    }

    getUserRefits = (payload?) => {
        payload = Object.assign({},
            this.props.user.userRefitSearchs,
            this.props.form.getFieldsValue());
        this.props.dispatch({
            type: "user/getUserRefits",
            payload
        });
    }

    userRefitDispose = (id) => {
        this.props.dispatch({
            type: "user/userRefitDispose",
            payload: {
                form: { id },
                callback: () => {
                    this.getUserRefits();
                }
            }
        });
    }

    reset = () => {
        this.props.form.resetFields();
    }

    render(): JSX.Element {
        //console.log(this.props);
        const { getFieldDecorator } = this.props.form;
        const { loading } = this.props;
        const {
            userRefits: { totalCount, items },
            userRefitSearchs: { pageIndex, pageSize } } = this.props.user;
        const pageChange = (pageIndex, pageSize) => {
            let payload = Object.assign({},
                this.props.user.userRefitSearchs,
                { pageIndex, pageSize });
            this.getUserRefits(payload);
        }
        const pagination: PaginationProps | boolean = {
            total: totalCount,
            defaultCurrent: 1,
            current: pageIndex,
            pageSize: pageSize,
            showSizeChanger: true,
            showTotal: (total) => `共 ${total} 条`,
            showQuickJumper: true,
            pageSizeOptions: ["10", "20", "30", "50"],
            onShowSizeChange: pageChange,
            onChange: pageChange
        };
        return (
            <Row className={Styles.F_BG_WHITE1}>
                <Row className={Styles.F_BG_WHITE}>
                    <Col span={24}>
                        <Form layout="inline">
                            <Form.Item label='状态'>
                                {getFieldDecorator('disposed', {
                                })(<Select style={{ width: 120 }}>
                                    <Select.Option value=''>全部</Select.Option>
                                    <Select.Option value='true'>已处理</Select.Option>
                                    <Select.Option value='false'>未处理</Select.Option>
                                </Select>)}
                            </Form.Item>
                            <Form.Item>
                                <Button size={size} type="primary" loading={loading} onClick={this.search}>查询</Button>
                            </Form.Item>
                        </Form>
                        <Col span={24}>
                            <hr className={Styles.hrBorder} />
                            <h3>改装车列表</h3>
                        </Col>
                        <Col span={24}>
                            <Table
                                dataSource={items}
                                bordered
                                pagination={pagination}
                                rowKey={(record: api.SingleUserMallUsersVOUserRefitVO) => String(record.id)}
                                loading={loading}
                            >
                                <Table.Column title="序号" key="no" render={(text, record, index) => {
                                    return (pageIndex - 1) * pageSize + index + 1
                                }} />
                                <Table.Column title="姓名" key="name" dataIndex="name" />
                                <Table.Column title="手机号" key="phoneNumber" dataIndex="phoneNumber" />
                                <Table.Column title="地址" key="address" dataIndex="address" />
                                <Table.Column title="状态" key="disposed" render={(text, record: api.SingleUserMallUsersVOUserRefitVO, index) => {
                                    return record.disposed ? '已处理' : '未处理'
                                }} />
                                <Table.Column title="描述" key="description" dataIndex="description" />
                                <Table.Column title="操作" render={(text, record: api.SingleUserMallUsersVOUserRefitVO, index) => {
                                    return (
                                        <div>
                                            {
                                                !record.disposed ?
                                                    (<a className={Styles.M_RIGHT} onClick={() => this.userRefitDispose(record.id)}>
                                                        处理
                                            </a>) : (undefined)
                                            }
                                        </div>
                                    );
                                }} />
                            </Table>
                        </Col>
                    </Col>
                </Row>
            </Row>)
    }
}

export default connect(({ user, loading: { models: { user: loading } } }) => ({ user, loading }))(Form.create()(Refits));
